package com.liqi.display.controller;


import com.liqi.display.common.Results;
import com.liqi.display.common.SystemCode;
import com.liqi.display.service.ITblOArchiveService;
import com.liqi.display.utils.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * 预约信息表
 * 汇总预约数：
 * 1.汇总当天预约数
 * 2.汇总当月预约数
 * 3.汇总今年预约数
 *
 * @author liqi
 * @since 2021-04-12
 */
@RestController
@RequestMapping("/tbl-oarchive")
public class TblOArchiveController {
    private static Logger logger= LoggerFactory.getLogger(TblOArchiveController.class);

    @Autowired
    ITblOArchiveService iTblOArchiveService;

    @GetMapping("total")
    public Results total(){

        //每天的统计
        Date day = DateUtil.getDay();
        int totalDay = iTblOArchiveService.total(day);


        //每月的统计
        Date month = DateUtil.getMonth();
        int totalMonth=iTblOArchiveService.total(month);

        //每年的统计
        Date year = DateUtil.getYear();
        int totalYear = iTblOArchiveService.total(year);
        Results results=new Results();
        try {
            Map<String,Integer> map=new ConcurrentHashMap<String,Integer>();
            map.put("day",totalDay);
            map.put("month",totalMonth);
            map.put("year",totalYear);
            logger.info("统计结果",map);
            results.setData(map);
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage(SystemCode.SYS_OK.getValue());
            return results;
        }catch (Exception e){
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setMessage(SystemCode.SYS_FAIL.getValue());
            logger.info("异常信息",e.getMessage());
            return results;
        }

    }


}
